<?php
class CV_Validate_Array_Depth extends CV_Validate_Abstract{
	var $_depth;
	public function __construct( $depth ){
		$this->_depth = $depth;
	}
	public function _isValid( $value ){
		if( !is_array($value) ){
			$this->_messages[] = "not an array";
			return false;
		}
		return $this->_validateDepthN( $value, $this->_depth );
	}
	protected function _validateDepthN( $value, $depth ){
		if( !is_array($value) ){
			if( ($depth) === 0 ){
				return true;
			} else {
				$this->_messages[] = "array is not deep enough";
				return false;
			}
		}
		if( is_array($value) && ($depth) === 0 ){
			$this->_messages[] = "array is deeper";
			return false;
		}
		foreach( $value as $elem ){
			if( !$this->_validateDepthN($elem, $depth-1) ){
				return false;
			}
		}
		return true;
	}
}